package com.luxondata.module.masterdata.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.luxondata.module.masterdata.entry.Distributor;
import com.luxondata.module.masterdata.repository.DistributorRepository;

@Component
public class DistributorService {

	@Autowired
	private DistributorRepository distRepository;

	public List getAll() {
		return distRepository.findAll();
	}

	/**
	 * 根据名称查询集合
	 * 
	 * @param name
	 * @return
	 */
	public List<Distributor> findByName(String name) {
		List<Distributor> dists = new ArrayList<Distributor>();
		dists = distRepository.findByName(name);
		return dists;
	}

	/**
	 * 根据编码查询集合
	 * 
	 * @param name
	 * @return
	 */
	public List<Distributor> findByNumber(String number) {
		List<Distributor> dists = new ArrayList<Distributor>();
		dists = distRepository.findByNumber(number);
		return dists;
	}

	/**
	 * 根据编码查询集合
	 * 
	 * @param name
	 * @return
	 */
	public List<Distributor> findByStatus(int status) {
		List<Distributor> dists = new ArrayList<Distributor>();
		dists = distRepository.findByStatus(status);
		return dists;
	}

	/**
	 * 根据主键查询
	 * 
	 * @param id
	 * @return
	 */
	public Distributor findById(long id) {
		return distRepository.findOne(id);

	}

	/**
	 * 保存实体对象
	 * 
	 * @param dist
	 * @return
	 */
	public Distributor save(Distributor dist) {
		return distRepository.save(dist);
	}

	/**
	 * 根据ID刪除某條記錄
	 * 
	 * @param id
	 */
	public void delete(long id) {
		distRepository.delete(id);
	}

	/**
	 * 根据实体刪除某條記錄
	 * 
	 * @param dist
	 */
	public void deleteByEntity(Distributor dist) {
		distRepository.delete(dist);
	}

}
